<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>

    <el-card>
      <el-row>
        <el-col :span="15">
          <el-input placeholder="请输入内容" v-model="queryInfo.query" clearable @clear="getorderlist">
            <el-button slot="append" icon="el-icon-search" @click="getorderlist"></el-button>
          </el-input>
        </el-col>
      </el-row>

      <el-table :data="orderlist" border stripe>
        <el-table-column type="index" label="#"></el-table-column>
        <el-table-column label="订单编号" prop="order_number"></el-table-column>
        <el-table-column label="订单价格" prop="order_price"></el-table-column>
        <el-table-column label="是否付款" prop="pay_status">
          <template slot-scope="scope">
            <el-tag type="danger" size="small" v-if="scope.row.pay_status === '0'">未付款</el-tag>
            <el-tag type="primary" size="small" v-else>已付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="是否发货" prop="is_send"></el-table-column>
        <el-table-column label="下单时间" prop="create_time"></el-table-column>
        <el-table-column label="操作" width="123px">
          <template slot-scope="scope">
            <el-button size="mini" type="primary" icon="el-icon-edit" @click="addressEdit(scope.row)"></el-button>
            <el-button size="mini" type="success" icon="el-icon-location" @click="addressEdit(scope.row)"></el-button>
          </template>
        </el-table-column>
      </el-table>

      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[3,5,8,10]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>

      <el-dialog
        title="提示"
        :visible.sync="adressdialogVisible"
        width="50%">
        <span>此功能由于数据问题暂未实现</span>
        <span slot="footer" class="dialog-footer">
          <el-button @click="adressdialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="adressdialogVisible = false">确 定</el-button>
        </span>
      </el-dialog>
    </el-card>
  </div>
</template>

<script>

export default {
  name: "Orderslist",
  data(){
    return {
      orderlist: [],
      total: 0,
      queryInfo: {
        query: '',
        pagesize: 10,
        pagenum: 1
      },
      adressdialogVisible: false,
    }
  },
  created() {
    this.getorderlist();
  },
  methods: {
    async getorderlist(){
      const {data: res} = await this.$http.get("/orders",{
        params: this.queryInfo
      })
      // console.log(res);
      if(res.meta.status !== 200) return this.$message.error("获取订单列表失败")
      this.orderlist = res.data.goods;
      this.total = res.data.total;
    },
    handleSizeChange(newsize){
      this.queryInfo.pagesize = newsize;
      this.getorderlist();
    },
    handleCurrentChange(newpage){
      this.queryInfo.pagenum = newpage;
      this.getorderlist();
    },

    addressEdit(row){
      this.adressdialogVisible = true;
    }
  }
}
</script>

<style scpoed>
  .el-card{
    margin: 30px 0px;
  }
  .el-row{
    margin: 20px 0px;
  }
  .el-table{
    margin: 30px 0px;
  }
</style>